/**
 *  Copyright (c) 2011, IPC Studio, USTC, All rights reserved
 *  FileName: Log.cpp
 *  Author: chengximing1989@gmail.com
 *  DateCreated: 2011-9-28
 */

#include "../include/Log.h"

LIBLYRICS_NAMESPACE_BEGIN

void CLog::LogDefault(int iLevel, const char *psz_fmt,...)
{
	va_list arg;
	va_start(arg, psz_fmt);

	char *psz_prefix;
	switch( iLevel )
	{
	case LOG_ERROR:
		psz_prefix = (char *)"error";
		break;
	case LOG_WARNING:
		psz_prefix = (char *)"warning";
		break;
	case LOG_INFO:
		psz_prefix = (char *)"info";
		break;
	case LOG_DEBUG:
		psz_prefix = (char *)"debug";
		break;
	default:
		psz_prefix = (char *)"unknown";
		break;
	}
	fprintf( stderr, "[%s]: ", psz_prefix );
	vfprintf( stderr, psz_fmt, arg );

}

void CLog::LogbyLevel( int iLevel, const char *psz_fmt,... )
{
	if (iLevel > m_iLogLevel)
	{
		return;
	}
	va_list arg;
	va_start(arg, psz_fmt);

	//logDefault(iLevel, psz_fmt, arg);
	char *psz_prefix;
	switch( iLevel )
	{
	case LOG_ERROR:
		psz_prefix = (char *)"error";
		break;
	case LOG_WARNING:
		psz_prefix = (char *)"warning";
		break;
	case LOG_INFO:
		psz_prefix = (char *)"info";
		break;
	case LOG_DEBUG:
		psz_prefix = (char *)"debug";
		break;
	default:
		psz_prefix = (char *)"unknown";
		break;
	}
	fprintf( stderr, "[%s]: ", psz_prefix );
	vfprintf( stderr, psz_fmt, arg );

}

void CLog::SetLogLevel( int iLevel )
{
	m_iLogLevel = iLevel;
}

int CLog::m_iLogLevel = LOG_INFO;

LIBLYRICS_NAMESPACE_END